home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / Media / DolphinTween2.vsh < prev    next >
Text File  |  2001-10-08  |  2KB  |  74 lines

  1. ;------------------------------------------------------------------------------
  2. ; Constants specified by the app
  3. ;    c0      = ( 0, 0, 0, 0 )
  4. ;    c1      = ( 1, 0.5, 2, 4 )
  5. ;    c2      = ( fWeight1, fWeight2, fWeight3, 0 )
  6. ;    c4-c7   = matWorldViewProjection
  7. ;    c8-c11  = matWorldView
  8. ;    c19     = light direction (in model space)
  9. ;    c21     = material diffuse color * light diffuse color
  10. ;    c22     = material ambient color
  11. ;
  12. ; Vertex components (as specified in the vertex DECL)
  13. ;    v0    = Position
  14. ;    v3    = Normal
  15. ;    v6    = Texcoords
  16. ;------------------------------------------------------------------------------
  17. vs.1.1
  18.  
  19. ;------------------------------------------------------------------------------
  20. ; Vertex transformation
  21. ;------------------------------------------------------------------------------
  22.  
  23. ; Tween the 3 positions (v0,v1,v2) into one position
  24. mul r0, v0, c2.x
  25. mul r1, v1, c2.y
  26. mul r2, v2, c2.z
  27. add r3, r0, r1
  28. add r3, r3, r2
  29.  
  30. ; Transform position to the clipping space
  31. m4x4 oPos, r3, c4
  32.  
  33. ; Transform position to the camera space
  34. m4x4 r9, r3, c8
  35.  
  36. ;------------------------------------------------------------------------------
  37. ; Lighting calculation
  38. ;------------------------------------------------------------------------------
  39.  
  40. ; Tween the 3 normals (v3,v4,v5) into one normal
  41. mul r0, v3, c2.x
  42. mul r1, v4, c2.y
  43. mul r2, v5, c2.z
  44. add r3, r0, r1
  45. add r3, r3, r2
  46.  
  47. ; Do the lighting calculation
  48. dp3 r1.x, r3, c19    ; r1 = normal dot light
  49. max r1.x, r1.x, c0.x   ; if dot < 0 then dot = 0
  50. mul r0, r1.x, c21    ; Multiply with diffuse
  51. add r0, r0, c22      ; Add in ambient
  52. min oD0, r0, c1.x    ; clamp if > 1
  53.  
  54.  
  55. ;------------------------------------------------------------------------------
  56. ; Texture coordinates
  57. ;------------------------------------------------------------------------------
  58.  
  59. ; Gen tex coords from vertex xz position
  60. mul oT0.xy, c1.y, r9.xz
  61.  
  62. ;------------------------------------------------------------------------------
  63. ; Fog calculation
  64. ;------------------------------------------------------------------------------
  65.  
  66. ; compute fog factor f = (fog_end - dist)*(1/(fog_end-fog_start))
  67. add r0.x, -r9.z, c23.y
  68. mul r0.x, r0.x, c23.z
  69. max r0.x, r0.x, c0.x       ; clamp fog to > 0.0
  70. min oFog.x, r0.x, c1.x     ; clamp fog to < 1.0
  71.  
  72.  
  73.  
  74.